$(function () {

    var permission_datagrid = $("#permission_datagrid");

    /*easyui的数据列表组件初始化*/
    permission_datagrid.datagrid({
        title:"权限管理",
        url: "/permission/query.do",
        fit: true,
        striped: true,
        pagination: true,
        rownumbers: true,
        fitColumns: true,
        singleSelect: true,
        toolbar: "#permission_toolbar",
        columns: [[
            {field: 'id', title: 'id', width: 100, checkbox: true},
            {field: 'name', title: '权限名称', width: 100},
            {field: 'resource', title: '权限资源', width: 100},
        ]]
    })


    /*事件对象*/
    var methodObj = {
        reload: function () {
            $("#permission_datagrid").datagrid("reload");
        },
        reload:function () {
            $.messager.confirm("温馨提示","确定要重新加载权限吗",function (tr) {
                if(tr){
                    $.get("/permission/reload.do",function (data) {
                        if(data.success){
                            $.messager.alert("温馨提示","加载成功","info",function () {
                                $("#permission_datagrid").datagrid('reload');
                            })
                        }else{
                            $.messager.alert("温馨提示","操作失败","error");
                        }
                    })
                }

            })

        }
    }


    /*统一绑定事件*/
    $("a[data-method]").click(function () {
        var method = $(this).data("method");
        methodObj[method]();
    })
})
